home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / RegionConverter.h < prev    next >
Text File  |  1995-06-12  |  6KB  |  209 lines

  1. /***********************************************************************\
  2. region converter for Convert PICT which converts graphics from PICT to eps formats.
  3. Copyright (C) 1993 David John Burrowes
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10.  
  11. The author, David John Burrowes, can be reached at:
  12.     davidjohn@kira.net.netcom.com
  13.     David John Burrowes
  14.     1926 Ivy #10
  15.     San Mateo, CA 94403-1367
  16. \***********************************************************************/
  17.  
  18.  
  19. #import "ResultObject.h"
  20. #import "common.h"
  21.  
  22.  
  23.  
  24. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. //    Definitions:    region types:
  26. //    Description:
  27. //        The following data types are used by the region converter when converting
  28. //        a Mac region into a set of coordinates for a PS description of the same.
  29. //    NOTE:
  30. //        Please read RegionConverter.rtf, since that describes much more about how
  31. //        this object behaves!
  32. //    Bugs:
  33. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34.  
  35. //
  36. //    A structure for describing an integral coordinate
  37. //
  38. typedef struct
  39. {
  40.     Integer x;
  41.     Integer y;
  42. }
  43. Coordinate;
  44.  
  45. //
  46. //    This is used to represent a segment where both coordinates reside on one y coordinate.
  47. //    Thus, one only needs to store the x values.  Note: left is always <= right
  48. //
  49. typedef struct
  50. {
  51.     Integer    left;
  52.     Integer    right;
  53. }
  54. Segment, * SegmentAddr;
  55.  
  56. #define    NullSegment    ((SegmentAddr) NULL)
  57.  
  58. //
  59. //    Used to build a chain of segments.
  60. //
  61. typedef struct SegmentLink
  62. {
  63.     Integer    left;
  64.     Integer    right;
  65.      struct SegmentLink*     nextSegment;
  66. }
  67. SegmentLink, *SegmentLinkAddr;
  68.  
  69. #define    EndOfChain    ((SegmentLinkAddr)  NULL)
  70.  
  71. //
  72. //    This describes a line segment as it is stored as part of a shape being accumulated.
  73. //    It stores the coordinates of the start and end of a line segment.  If it has been
  74. //    connected to another line segment, the left and right pointers refer to other lines it
  75. //    has been attached to. (left < right.  If line is vertical, left means top, right means bottom,
  76. //    since top < bottom).   If a shape is incomplete, then it may not be connected to another
  77. //    line on one or both sides, but a segment on the `active' list may point to it.
  78. //
  79. typedef struct LineSegment *LineSegmentAddr;
  80. typedef struct LineSegment
  81. {
  82.     Coordinate    left;
  83.     Coordinate    right;
  84.     LineSegmentAddr        leftNext;
  85.     LineSegmentAddr        rightNext;
  86.     Boolean                used;    // used to mark that this linesegment has been touched.
  87. } LineSegment;
  88.  
  89. #define    NoLine    ((LineSegmentAddr) NULL)
  90.  
  91. //
  92. //    If a segment of a line/space is being considered, then an ActiveSegment is stored on
  93. //    the Active list.  Such a segment consists of a left and right x coordinate, and pointers
  94. //    to the line or lines that the area this segment will attach to.
  95. //
  96. typedef struct ActiveSegment * ActiveSegmentAddr;
  97. typedef struct ActiveSegment
  98. {
  99.     Integer                left;
  100.     Integer                right;
  101.     LineSegmentAddr        leftLine;
  102.     LineSegmentAddr        rightLine;
  103.     ActiveSegmentAddr    next;
  104.     ActiveSegmentAddr    previous;
  105. }
  106. ActiveSegment;
  107.  
  108. #define    EndOfActiveList    ((ActiveSegmentAddr) NULL)
  109.  
  110. //
  111. //    each SegmentGroup holds all the segments, from the region data, that occurr on
  112. //    one Y coordinate.  So, this stores the y they occrr on, the chain of segments, and a
  113. //    pointer to the next segment.
  114. //
  115.  
  116. typedef struct SegmentGroup *SegmentGroupAddr;
  117. typedef struct SegmentGroup
  118. {
  119.     Integer                y;
  120.     SegmentLinkAddr    segmentData;
  121.     SegmentGroupAddr    next;
  122. }
  123. SegmentGroup;
  124.  
  125. #define    EndOfGroups    NULL
  126.  
  127.  
  128. //
  129. //    This stucture is used to hold the shapes that are built from the REgion data
  130. //    It holds a pointer to the next shape, and a pointer to the first line segment of the shape.
  131. typedef struct Shape *ShapeAddr;
  132. typedef struct Shape
  133. {
  134.     LineSegmentAddr        theLine;
  135.     ShapeAddr            nextShape;
  136. } Shape;
  137.  
  138. #define    NoShape    ((ShapeAddr) NULL)
  139.  
  140. //
  141. //    Define kinds of segment intersection
  142. //
  143. typedef enum
  144. {
  145.     None,
  146.     TouchOuterLeft, TouchOuterRight,
  147.     TouchInnerLeft, TouchInnerRight,
  148.     TouchInnerLeftExtendRight, TouchInnerRightExtendLeft,
  149.     LeftOverlap, RightOverlap,
  150.     Larger, Within,
  151.     Equal
  152. }
  153. OverlapKind;
  154. //
  155. //    Used to store what direction a routine is `moving' in.
  156. //
  157. typedef enum
  158. {
  159.     toLeft, toRight
  160. }
  161. DirectionType;
  162.  
  163. #define    EndOfRegion    32767
  164. #define    EndOfRegionLine    32767
  165.  
  166.  
  167. @interface regionConverter:ResultObject
  168. {
  169.     ActiveSegmentAddr    ActiveList;
  170.     ShapeAddr            ShapeStorage;
  171.     SegmentGroupAddr    RegionData;
  172.     PICTRect*            boundsRect;
  173. }
  174.  
  175. - ConvertRegionFrom: PictFile  To: PsFile;
  176. - ReadInRegionFrom: PictFile;
  177. - ConvertRegionData;
  178. -WriteTo: PsFile;
  179. - WriteShapeFromLine:  (LineSegmentAddr) startLine  To: PsFile;
  180.  
  181. - (OverlapKind) CheckHowSegment: (SegmentAddr) segment
  182.                         Intersects: (ActiveSegmentAddr) active;
  183.  
  184. -AddSegmentFrom: (Integer) left  To: (Integer) right  ToGroup: (SegmentGroupAddr) group;
  185. -(SegmentAddr) GetNextSegmentFromGroup: (SegmentGroupAddr) group;
  186.  
  187. - AddShapeFrom: (Integer) left  To: (Integer) right  At: (Integer) y;
  188. -(LineSegmentAddr) AddAntiShapeFrom: (Integer) left  To: (Integer) right  At: (Integer) y;
  189.  
  190. - (LineSegmentAddr)  AddLineFrom: (Integer) left  To: (Integer) right  At: (Integer) y
  191.     WithLeft: (LineSegmentAddr) leftline  AndRight: (LineSegmentAddr) rightline;
  192.  
  193. - AddActiveFrom: (Integer) left  To: (Integer) right  WithLeft:
  194.         (LineSegmentAddr) leftline  AndRight: (LineSegmentAddr) rightline;
  195. - RemoveActive: (ActiveSegmentAddr) theActive;
  196. - (ActiveSegmentAddr) FindFirstActiveLeftIn: (Integer) left  To: (Integer) right;
  197. - CleanUp;
  198. @end
  199.  
  200.  
  201.  
  202. #define    ERR_BADDATA    -1000
  203. #define    ERR_WEIRDDATA    1000
  204. #define    ERR_BADSIZE    500
  205. #define    ERR_NOSEGMENTS    100
  206.  
  207.  
  208.  
  209.